class Solution {
    public int lengthOfLongestSubstring(String s) {
        int[] m = new int[128];
        int n = s.length(), rk = 0, ans = 0;
        for (int i = 0; i < n; i++) {
            if (m[s.charAt(i)] > rk) {
                if (ans < i - rk) {
                    ans = i - rk;
                }
                rk = m[s.charAt(i)];
            }
            m[s.charAt(i)] = i + 1;
        }
        return Math.max(ans, n - rk);
    }
}